<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width =device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <link rel="stylesheet" href="/css/global.css"/>
    <script src="/layui/layui.all.js"></script>
    <script src="/js/jquery-3.2.1.min.js"></script>
    <script src="/js/global.js"></script>
    <title>登录界面</title>
</head>
<body class="layui-bg-green">

<div style="margin-top: 80px"></div>

<div class="layui-row">
    <div class="layui-col-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12 ">
        <div class="layui-form-item ">
            <h1 class="lk-center-outside">
                后台管理系统</h1>
        </div>
    </div>
</div>

<div id="app" class="layui-row layui-fluid" style="margin-top: 50px">
    <div class="layui-col-xs12 layui-col-sm8 layui-col-sm-offset2 layui-col-md12 layui-col-lg4 layui-col-lg-offset4">
        <div class="lk-center-inside">
            <label class="layui-form-label layui-clear">账号</label>
            <input id="uname" type="text" name="uname" lay-verify="required" placeholder="请输入用户名"
                   autocomplete="off" class="layui-input"/>
        </div>
        <div class="lk-height40"></div>
        <div class="lk-center-inside ">
            <label class="layui-form-label">密码</label>
            <input id="passwd" type="password" name="passwd" lay-verify="required" placeholder="请输入密码"
                   autocomplete="off" class="layui-input"/>
        </div>
        <div class="lk-height40"></div>
        <div class="lk-center-outside">
            <button onclick="login()" class="layui-btn layui-btn-normal">登录
            </button>
        </div>
    </div>
</div>

<script type="text/javascript">

    $('#passwd').bind('keypress', function (event) {
        if (event.keyCode == "13") {
            //需要处理的事情
            login()
        }
    });

    function login() {
        var name = $('#uname').val();
        var passwd = $('#passwd').val();
        var data = {"name": name, "passwd": passwd};
        console.log(data)
        $.ajax({
            url: "/sys/staff/login",
            global: true,
            type: "POST",
            data: data,
            success: function (data) {
                if (data.code == 0) {
                    layer.msg('登录成功');
                    sessionStorage.setItem("token", data.data)
                    window.location.href="/home?token="+data.data;
                } else {
                    layer.msg(data.message);
                }
            }
        });
    }
</script>

</body>
</html>